<template>
  <div>
    <el-divider content-position="left">价格项</el-divider>
    <el-row v-for="(item,index) in priceGroup" :key="index">
      <el-col :span="3" style="text-align: center;">
        <el-form-item label-width="0"> {{item.priceGroupName}} </el-form-item>
      </el-col>
      <el-col :span="5">
        <el-form-item label="税率" :prop="'list.'+index+'.taxRate'" :rules="productGroupRules.productGroupRate">
          <el-input v-model="item.taxRate"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="5">
        <el-form-item label="成本单价">
          <el-input v-model="item.notTaxPrice"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="5">
        <el-form-item label="含税单价" :prop="'list.'+index+'.taxPrice'" :rules="productGroupRules.productGroupNum">
          <el-input v-model="item.taxPrice"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="5">
        <el-form-item label="零售价格" :prop="'list.'+index+'.price'" :rules="productGroupRules.productGroupPrice">
          <el-input v-model="item.price"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import { filterParams } from '@/util/tools'

  export default {
    props: ['priceGroup'],
    data() {
      return {
        productGroupRules: {
          productGroupRate: [
            {required: true, message: '请填写该价格组税率', trigger: 'blur'},
            {trigger: 'change',message: '税率必须为整数(1~2位数)',pattern:/^[0-9]\d{0,1}$/}
          ],
         productGroupNum: [
           {required: true, message: '请填写含税价格', trigger: 'blur'},
           {trigger: 'change',message: '只能保留两位位小数',pattern:/^([0-9]\d*)(\.\d{0,2})?$/}
         ],
         productGroupPrice: [
           {required: true, message: '请填写零售价格', trigger: 'blur'},
           {trigger: 'change',message: '只能保留两位位小数',pattern:/^([0-9]\d*)(\.\d{0,2})?$/}
         ]
        }
      }
    },
    computed: {
      ...mapGetters(['permissions']),
    },
    created() {
      this.priceGroup.forEach(item => {
        if(item.taxRate){
          this.$set(item,'taxRate', '13')
        }
      })
    },
    methods: {

    }
  }
</script>
